package com.hospital.controller;

import com.hospital.domain.DTO.DoctorDTO;
import com.hospital.domain.pojo.Doctor;
import com.hospital.domain.utils.Result;
import com.hospital.service.DoctorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/doctor")
@Tag(name = "医生接口", description = "无")
public class DoctorController {

    private final DoctorService doctorService;

    @Operation(summary = "根据科室id查看医生")
    @GetMapping("/query/{depId}")
    public Result queryDoctor(@PathVariable("depId") Integer depId){
        return doctorService.queryDoctor(depId);
    }

    @Operation(summary = "获取所有医生")
    @GetMapping("/query")
    public Result queryAllDoctors(){
        return doctorService.queryAllDoctors();
    }

    @Operation(summary = "查看医生信息")
    @GetMapping("/info/{DId}")
    public Result getDoctor(@PathVariable("DId") Integer DId){
        Doctor doctor = doctorService.lambdaQuery().eq(Doctor::getDId, DId).one();
        if(doctor == null){
            return Result.fail("该医生不存在");
        }
        return Result.ok(doctor);
    }

    @Operation(summary = "注册医生账号(不能出现同名医生)")
    @PostMapping("/signup")
    public Result signupDoctor(@RequestBody DoctorDTO doctorDTO){
        return doctorService.signupDoctor(doctorDTO.getName(), doctorDTO.getSex(), doctorDTO.getAge(), doctorDTO.getTitle(), doctorDTO.getMajor(), doctorDTO.getInfo(), doctorDTO.getState(), doctorDTO.getDepName(), doctorDTO.getPw());
    }

    @Operation(summary = "更新医生信息")
    @PutMapping("/update")
    public Result updateDoctor(@RequestBody DoctorDTO doctorDTO){
        return doctorService.updateDoctor(doctorDTO.getDId(), doctorDTO.getName(), doctorDTO.getSex(), doctorDTO.getAge(), doctorDTO.getTitle(), doctorDTO.getMajor(), doctorDTO.getInfo(), doctorDTO.getState(), doctorDTO.getDepName());
    }

    @Operation(summary = "删除医生")
    @DeleteMapping("/delete/{dId}")
    public Result deleteDoctor(@PathVariable("dId") Integer dId){
        return doctorService.deleteDoctor(dId);
    }
}
